<?php
include FB_ABSPATH."/db/opendb.php";
include FB_ABSPATH."/facebook/classes/Paginator.class.php";
$sql = "select p.* from PROPERTIES p inner join Prop_Owner_Con c on p.OID = c.Prop_OID where c.Owner = '".$_SESSION['id']."' and LISTSTATUS = 'Active'";
$rs = mysql_query($sql);
$total_recs = mysql_num_rows($rs);
$limit = 5;
$from = isset($_GET['page_'])?(int)$_GET['page_']:1;

$offset = ($from-1)*$limit;

$mquery = "select p.* from PROPERTIES p inner join Prop_Owner_Con c on p.OID = c.Prop_OID where c.Owner = '".$_SESSION['id']."' and LISTSTATUS = 'Active' ORDER BY sort_order LIMIT $offset, $limit";
$mresult = mysql_query($mquery) or die ("SQL Error".mysql_error());

$params = $_GET;
$pagination = Paging::getPaging1($total_recs, $limit, $params, CANVAS_URL);
?>
<div class="list_head">Active Listings</div>
<?php echo $pagination?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
<?php
if(mysql_num_rows($mresult))
{
	while ($row = mysql_fetch_assoc($mresult))
	{
//		echo "<pre>";print_r($row);
		$query = "select * from Listing_Images where Listing_ID = '".$row['OID']."' and Main_Photo = 1";
		$result = mysql_query($query) or die ("SQL Error".mysql_error());
		$lrow = mysql_fetch_assoc($result);
		if($lrow['Path']!='')
		{
			$img_url = SITE_URL."/listing_images/t_".$lrow['Path'];
		}
		else
		{
			$img_url = "http://www.realivent.com/listing_images/nia_thumb.gif";
		}
		$title = $row['STREETNUM']." ".$row['STREETNAME']." ".$row['STREETSUFFIX'].", ".$row['CITY']." ".$row['STATE'];
		$url = SITE_URL."/listing_details.php?listing_id=".$row['OID'];
		$description = $row['BEDS'] ." Beds | ".$row['BATHSTOTAL']." Baths | ".number_format($row['SQFTTOTAL'], 0)." SQFT | Covered Parking: ".$row['PARKINGCOVERED'];
		$price = number_format($row['LISTPRICE'], 0);
		$listing_detail_url = ($row['custom_url'])?$row['custom_url']:SITE_URL."/vt/{$row['OID']}";
		?>
		<TR>
			<TD width="120">
				<img style="border:1px solid black;" src=<?php echo $img_url?>>
			</TD>
			<TD>
				<div class="list_title"><?php echo $title ?></DIV>
				<div><?php echo $description?></div>
				<div><b>Price:</b> $<?php echo number_format($row['LISTPRICE'], 0) ?></div>
				<div><a href="<?php echo $listing_detail_url?>" target="_blank">View Listing</a><!-- | <a href="javascript:;" onclick="fb_publish('<?php echo $img_url?>', '<?php echo $title?>', '<?php echo $url?>', '<?php echo $description?>', '<?php echo $price?>')">Post to Newsfeed</a>--></div>
			</TD>
		</TR>
		<?php
	}
}
else {
	echo "<tr><td>No listings found</td></tr>";
}
?>
</table>
<div>
<a href="<?php echo APLICATION_PROFILE_URL?>" target="_blank">View the Application</a>
</div>